package ws.jdbc.concurrent.eresultset;

import java.sql.SQLException;

/**
 * Result set cursor.
 *
 * @author Wilson Santos, 36228 <wilson.santos@ua.pt>
 */
public class Cursor implements ICursor {

  /** {@link EResultSet} object that this cursor will work upon. */
  protected final EResultSet rs;
  /** Cursor ID. */
  protected final int id;

  /**
   * Create new instance.
   *
   * @param rs {@link EResultSet} object that this cursor will work upon.
   */
  protected Cursor(final EResultSet rs, final int id) {
    this.id = id;
    this.rs = rs;
  }

  public boolean absolute(int row) throws SQLException {
    return rs.absolute(id, row);
  }

  public void afterLast() throws SQLException {
    rs.afterLast(id);
  }

  public void beforeFirst() throws SQLException {
    rs.beforeFirst(id);
  }

  public boolean previous() throws SQLException {
    return rs.previous(id);
  }

  public boolean relative(int rows) throws SQLException {
    return rs.relative(id, rows);
  }

  public boolean next() throws SQLException {
    return rs.next(id);
  }

  public int getInt(int columnIndex) throws SQLException {
    return rs.getInt(id, columnIndex);
  }

  public String getString(int columnIndex) throws SQLException {
    return rs.getString(id, columnIndex);
  }

  public float getFloat(int columnIndex) throws SQLException {
    return rs.getFloat(id, columnIndex);
  }

  public void moveToInsertRow() throws SQLException {
    rs.moveToInsertRow(id);
  }

  public void moveToCurrentRow() throws SQLException {
    rs.moveToCurrentRow(id);
  }

  public void cancelRowUpdates() throws SQLException {
    rs.cancelRowUpdates(id);
  }

  public void updateFloat(int columnIndex, float x) throws SQLException {
    rs.updateFloat(id, columnIndex, x);
  }

  public void updateInt(int columnIndex, int x) throws SQLException {
    rs.updateInt(id, columnIndex, x);
  }

  public void updateString(int columnIndex, String x) throws SQLException {
    rs.updateString(id, columnIndex, x);
  }

  public void updateRow() throws SQLException {
    rs.updateRow(id);
  }

  public void insertRow() throws SQLException {
    rs.insertRow(id);
  }

  public int getRow() throws SQLException {
    return rs.getRow(id);
  }

  public boolean isAfterLast() throws SQLException {
    return rs.isAfterLast(id);
  }

  public boolean isBeforeFirst() throws SQLException {
    return rs.isBeforeFirst(id);
  }

  public void lock() {
    rs.lock();
  }

  public void unlock() {
    rs.unlock();
  }
}
